package ac.il.technion.cs236635.project.core;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.xml.ws.Endpoint;

import org.apache.log4j.Logger;

public class Client {
	
	public static void main(String[] args) {
		Logger log = Logger.getLogger( Client.class);
		BufferedReader reader = new BufferedReader( new InputStreamReader( System.in));
		ExecutorService pool = Executors.newFixedThreadPool(3);
		WatchDog watchDog = new WatchDog();
		JobsSubmitter submitter = new JobsSubmitter( );
		JobsSender sender = new JobsSender( );
		Properties properties = new Properties( );
		try {
			properties.load( Client.class.getClassLoader().getResourceAsStream( "client.properties"));
		} catch (IOException e1) {
			log.error( e1);
		}
		Endpoint endpoint = Endpoint.create(  new ResultListener( ));
		endpoint.publish( properties.getProperty( "clientEndpoint"));
		pool.execute(watchDog);
		pool.execute(submitter);
		pool.execute( sender);
		String line = "";
		while ( !line.equals( "exit")) {
			try {
				line = reader.readLine( );
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		watchDog.finish( );
		sender.finish( );
		submitter.finish();
		pool.shutdown( );
	}
}